/**
 * Created With IntelliJ IDEA
 * Description:牛客网:BM87 合并两个有序的数组
 * <a href="https://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665?tpId=295&tqId=658&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj"></a>
 * User: DELL
 * Data: 2023-03-07
 * Time: 22:06
 */
public class Solution {
    public void merge(int A[], int m, int B[], int n) {
        int index = m + n;
        while (m > 0 && n > 0) {
            if (A[m-1] >= B[n-1]) {
                A[--index] = A[--m];
            } else {
                A[--index] = B[--n];
            }
        }
        //这里当A中有剩余元素的时候不用管,因为这些元素正好再A中,且为有序的
        if(n > 0) {
            while(n > 0) {
                A[--index] = B[--n];
            }
        }
    }
}